<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://api.mapbox.com/mapbox-gl-js/v2.9.1/mapbox-gl.css" rel="stylesheet">
    <script src="https://api.mapbox.com/mapbox-gl-js/v2.9.1/mapbox-gl.js"></script>
    <script src='https://unpkg.com/@antv/l7'></script>
    <style>
        html,
        body {
            overflow: hidden;
            margin: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script>
        mapboxgl.accessToken = 'pk.eyJ1IjoiY2hlbmdiZW5jaGFvIiwiYSI6ImNsODU3aGRiODA0Y2UzcHBzZmFlcmdqZ2sifQ.8k59W_pB_Riwe6o-MneRlA'
        const map = new mapboxgl.Map({
            container: 'map', // container id
            style: 'mapbox://styles/mapbox/dark-v10', // stylesheet location
            pitch: 50,
            center: [118.8, 32.056],
            zoom: 8,
            projection: "globe"
        });
        const { Scene, Mapbox, PolygonLayer } = L7;
        const scene = new Scene({
            id: 'map',
            map: new Mapbox({
                mapInstance: map,
            }),
        });
        const colors = [
            '#87CEFA',
            '#00BFFF',

            '#7FFFAA',
            '#00FF7F',
            '#32CD32',

            '#F0E68C',
            '#FFD700',

            '#FF7F50',
            '#FF6347',
            '#FF0000',
            '#FF2D51'
        ];
        scene.on('loaded', () => {
            fetch(
                'https://gw.alipayobjects.com/os/bmw-prod/94763191-2816-4c1a-8d0d-8bcf4181056a.json'
            )
                .then(res => res.json())
                .then(data => {
                    console.log(data)
                    const filllayer = new L7.PolygonLayer({
                        name: 'fill',
                        zIndex: 3
                    })
                        /* source 使用标准的geojson */
                        .source(data)
                        /* 将数据沿着z轴线拉升增加高度 */
                        .shape('extrude')
                        /* size 代表拉伸的高度，支持数据映射 */
                        .size('unit_price', unit_price => {
                            console.log(unit_price)
                            return unit_price / 2
                        })
                        /* 设置数据的样式 */
                        .style({
                            opacity: ['unit_price', [0.6, 1]],
                            pickLight: true
                        })
                        /* 根据数据的某个字段 设置数据的颜色 */
                        .color('unit_price', colors)
                        /* 让数据高亮 */
                        .active(true);
                    scene.addLayer(filllayer);
                });
        });

    </script>
</body>

</html>